import axios from 'axios'

const service = axios.create({
  timeout: 5000
})
export default{
  get (url, param) {
    return new Promise((resolve, reject) => {
      service({
        method: 'get',
        url,
        params: param
      }).then(res => { // axios返回的是一个promise对象
        resolve(res) // resolve在promise执行器内部
      }).catch(err => {
        console.log(err, '请求异常')
      })
    })
  },
  post (url, param) {
    return new Promise((resolve, reject) => {
      service({
        method: 'post',
        url,
        data: param
      }).then(res => { // axios返回的是一个promise对象
        resolve(res) // resolve在promise执行器内部
      }).catch(err => {
        console.log(err, '请求异常')
      })
    })
  }
}
